package com.hd.view.action;

import java.util.List;

import com.hd.common.Common;
import com.hd.common.DataPage;
import com.hd.persistence.model.Appraisal;
import com.hd.persistence.model.Customer;
import com.hd.persistence.model.Machine;
import com.hd.persistence.model.Person;
import com.hd.persistence.model.ReturnRecord;

/**
 * 回访单
 * @author jiaoyang
 *
 */
public class VisitAction extends BaseAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private ReturnRecord returnRecord;
	/*客户名*/
	private List<Customer> customers;
	/*机型*/
	private List<Machine> machines;
	/*维修人员*/
	private List<Person> maintenanceMen;
	/*维修时间*/
	private String thisTimeRepairDate;
	/*维修后评价*/
	private Appraisal appraisal;
	/*查询出的回访单*/
	private DataPage<ReturnRecord> returnRecords;
	
	/**增加新的回访单
	 * @return
	 * @throws Exception
	 */
	public String addNewReturnRecord() throws Exception{
		/*列出所有客户*/
		customers = purchaseManager.listCustomers();
		/*列出所有维修员*/
		maintenanceMen = memberManager.listPerson(2,false);
		/*列出所有机器*/
		machines = memberManager.listMachine();
		return SUCCESS;
	}
	
	/**保存回访单
	 * @return
	 * @throws Exception
	 */
	public String saveReturnRecord() throws Exception{
		returnRecord.setThisTimeRepairDate(Common.String2Date(thisTimeRepairDate));
		returnRecord.setCreateTimestamp(System.currentTimeMillis());
		repairManager.saveReturnRecord(returnRecord);
		
		//保存客户评价
		appraisal.setReturnRecord(returnRecord);
		repairManager.saveAppraisal(appraisal);
		statusTemp = true;
		return SUCCESS;
	}
	
	public String listReturnRecords() throws Exception{
		/*列出所有客户*/
		customers = purchaseManager.listCustomers();
		/*列出所有机器*/
		machines = memberManager.listMachine();
		/*列出所有维修员*/
		maintenanceMen = memberManager.listPerson(2,false);
		
		if(returnRecord == null){
			returnRecord = new ReturnRecord();
		}
		returnRecords = repairManager.pageQueryReturnRecords(returnRecord.getUnitName(), returnRecord.getMachineModel(), returnRecord.getThisTimeRepairman(), Common.String2Date(thisTimeRepairDate), getCurrentPage(), pageSize);
		setTotalPage(returnRecords.getTotalPageCount());
		return SUCCESS;
	}

	
/*=================get,set方法================================================*/	
	public ReturnRecord getReturnRecord() {
		return returnRecord;
	}
	
	public void setReturnRecord(ReturnRecord returnRecord) {
		this.returnRecord = returnRecord;
	}

	public List<Customer> getCustomers() {
		return customers;
	}

	public void setCustomers(List<Customer> customers) {
		this.customers = customers;
	}

	public List<Machine> getMachines() {
		return machines;
	}

	public void setMachines(List<Machine> machines) {
		this.machines = machines;
	}

	public List<Person> getMaintenanceMen() {
		return maintenanceMen;
	}

	public void setMaintenanceMen(List<Person> maintenanceMen) {
		this.maintenanceMen = maintenanceMen;
	}

	public String getThisTimeRepairDate() {
		return thisTimeRepairDate;
	}

	public void setThisTimeRepairDate(String thisTimeRepairDate) {
		this.thisTimeRepairDate = thisTimeRepairDate;
	}

	public Appraisal getAppraisal() {
		return appraisal;
	}

	public void setAppraisal(Appraisal appraisal) {
		this.appraisal = appraisal;
	}

	public DataPage<ReturnRecord> getReturnRecords() {
		return returnRecords;
	}

	public void setReturnRecords(DataPage<ReturnRecord> returnRecords) {
		this.returnRecords = returnRecords;
	}
	
}
